//
//  JOStatuseCell.m
//  微博
//
//  Created by song on 15/1/13.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOStatuseCell.h"
#import "JOStatus.h"
#import "JOStatuseFrame.h"
#define JONameFont [UIFont systemFontOfSize:14]


@interface JOStatuseCell()

@property (nonatomic ,weak )UIImageView *iconview;

@property (nonatomic ,weak )UILabel *nameview;

@property (nonatomic ,weak )UIImageView *vipview;

@property (nonatomic ,weak )UILabel *textview;

@property (nonatomic ,weak )UIImageView *picview;

@end



@implementation JOStatuseCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//+(instancetype)cellWithTableView:(UITableView *)tableView
//{
//    
//}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if(self)
    {
        UIImageView *iconview = [[UIImageView alloc]init];
        [self.contentView addSubview:iconview];
        self.iconview  = iconview;
        
        
        UILabel *nameview = [[UILabel alloc]init];
        nameview.font =JONameFont;
        [self.contentView addSubview:nameview];
        self.nameview = nameview;
//        [self.nameview setBackgroundColor:[UIColor yellowColor]];
        
        UIImageView *vipview = [[UIImageView alloc]init];
        [self.contentView addSubview:vipview];
        self.vipview = vipview;
     
        
        UILabel *textview = [[UILabel alloc]init];
        textview.numberOfLines = 0;
        textview.font =JONameFont;
        [self.contentView addSubview:textview];
        self.textview = textview;
//        [self.textview setBackgroundColor:[UIColor blueColor]];
        
        UIImageView *picview = [[UIImageView alloc]init];
        [self.contentView addSubview:picview];
        self.picview = picview;
        
    }
    
    return self;
    
}

-(void)setStatusFrame:(JOStatuseFrame *)statusFrame
{
    _statusFrame = statusFrame;
    [self settingData];
    [self setFrame];
}



-(void)settingData
{
    
    JOStatus *status = self.statusFrame.status;
    self.iconview.image = [UIImage imageNamed:status.icon];
    
    self.nameview.text = status.name;
    
    
    
    if(status.vip)
    {
        self.vipview.hidden =NO;
        self.vipview.image = [UIImage imageNamed:@"vip"];
    }else{
        self.vipview.hidden =YES;
    }
    
    self.textview.text = status.text;
    
    if(status.picture)
    {
        self.picview.hidden =NO;
        self.picview.image = [UIImage imageNamed:status.picture];
    }else{
        self.picview.hidden=YES;
    }
    
    
}

-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
        NSDictionary *attrs =@{NSFontAttributeName :font};
      return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


-(void)setFrame
{

    
    self.iconview.frame = self.statusFrame.iconF;
    

    

    self.nameview.frame =  self.statusFrame.nameF;
    

    self.vipview.frame = self.statusFrame.vipF;
    

    self.textview.frame = self.statusFrame.textF;
    
    
  
    self.picview.frame = self.statusFrame.pictureF;

    
    
}


@end
